import { result } from 'lodash';
/*
 * @Description: 
 * @Autor: 商晓彬
 * @Date: 2021-08-09 08:57:57
 * @LastEditors: 商晓彬
 * @LastEditTime: 2022-01-04 14:29:40
 */
import { AfterViewChecked, Component, ElementRef, EventEmitter, Injector, Input, Output, ViewChild } from '@angular/core';
import { AppComponentBase } from '@shared/common/app-component-base';
import { BopDescEditDto, BopDescServiceProxy, CreateOrUpdateBopDescInput, BopNodeServiceProxy, FilesTransferServiceProxy } from '@shared/service-proxies/service-proxies';
import { ModalDirective } from 'ngx-bootstrap';
import { IOrganizationUnitsTreeComponentData, OrganizationUnitsTreeComponent } from '../../shared/organization-unit-tree.component';
import * as _ from 'lodash';
import { finalize } from 'rxjs/operators';
import { MessageService } from '@abp/message/message.service';
@Component({
    selector: 'app-data-export',
    templateUrl: './data-export.component.html',
    styleUrls: ['./data-export.component.less']
})
export class DataExportComponent extends AppComponentBase {
    //引入子组件
    @ViewChild('createOrEditModal') modal: ModalDirective;
    //父组件传递的参数
    @Input() params: any;
    @Output() modalSave: EventEmitter<any> = new EventEmitter<any>();
    saving = false;
    active = false;
    //加载
    isLoading: boolean = false
    //表格单选的数据
    selectedItem: any;
    //表格
    tableData: any;
    form: BopDescEditDto = new BopDescEditDto();
    saveFlag = true;
    constructor(
        injector: Injector,
        private _bopDescServiceProxy: BopDescServiceProxy,
        private _messageService: MessageService,
        private _bopNodeServiceProxy: BopNodeServiceProxy,
        private _filesTransfer: FilesTransferServiceProxy
    ) {
        super(injector);
        this.saving = false;
    }
    //导出
    save(): void {
        // if (this.saveFlag) {
        //     this.saveFlag = false;
            //获取实体
            let input = new CreateOrUpdateBopDescInput();
            //将form表单赋值给input的bopdesc下
            input.bopDesc = this.form;
            this.saving = true;
            this._bopDescServiceProxy.createOrUpdateBopDesc(input);
            this._bopNodeServiceProxy.padSenFile(
                this.params.processId, this.params.nodeLevel, this.selectedItem.ipAddress, this.selectedItem.port, this.params.id, this.selectedItem.padID, this.selectedItem.padName
            )
                .pipe(finalize(() => { }))
                .subscribe(result => {
                    this.saveFlag = false;
                    if (result.code == 0) {
                        this._messageService.success('导出成功');
                        this.close();
                        this.modalSave.emit(null);
                    } else {
                        this._messageService.error(result.message)
                    }

                });
        // }
    }
    //打开弹窗
    onShown(): void {
        this.saving = false;
        // document.getElementById('model').focus();
    }
    //查看新增任务
    show(): void {
        this.active = true;
        this.modal.show();
        this.getTableInfo()
    }
    //获取表格数据
    getTableInfo(): void {
        this.isLoading = true
        this._filesTransfer.getHeartBeatList().pipe(finalize(() => { }))
            .subscribe(result => {
                this.isLoading = false;
                this.tableData = result
            })
    }
    //关闭事件
    close(): void {
        //清空form表单
        this.selectedItem = {};
        this.form = new BopDescEditDto();
        this.active = false;
        this.saving = false;
        this.modal.hide();
    }


}
